var util = require('../../utils/util.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin:false,
    isAdmin:false,
    groupName: null,
    groupList:[],
    paging: { height: 0, page: 1, limit: 10, totalPage: 0 },
  },
  inputTyping:function(e){
    var value = e.detail.value;
    this.setData({ groupName:value});
  },
  search:function(){
    this.loadPageData();
  },
  reloadData: function () {
    this.loadPageData();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '团购列表',
    });
   
    var that = this;
    wx.getSystemInfo({
      success: (res) => {
        that.setData({
          "paging.height": res.windowHeight
        })
      }
    })
    this.loadPageData();
  },
  toGroupInfo:function(e){
    var groupId = e.currentTarget.dataset.groupid;
    wx.navigateTo({
      url: 'group-info?groupId=' + groupId,
      fail:function(e){
        console.log(e);
      }
    })
  },
  toGroupEdit: function (e) {
    var url ="group-edit";
    if (e.currentTarget.dataset.groupid){
      url = url+'?groupId=' +  e.currentTarget.dataset.groupid;
    }
    wx.navigateTo({
      url: url
    })
  },
  nextPage: function () {
    var that = this;
    util.nextPage(function (param) {
      that.loadPageData();
    });
  },
  loadPageData:function(){
    var param={};
    if(this.data.groupName){
      param.groupName = this.data.groupName;
    }
    util.pagingPost({
      uri: '/group/group/list',
      params: param,
      dataList: 'groupList',
      thatPage:this
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var b = app.isLogin();
    if (this.data.isLogin != b) {
      var isAdmin = app.getMerchantId() > 0 ? true : false;
      this.setData({ "isLogin": b, "isAdmin":isAdmin});
      this.loadPageData();
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})